package com.wanban.m3u8download

import android.content.Context
import android.view.ViewGroup
import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.wanban.download.db.DownloadEntity
import com.wanban.download.model.Status

class DownloadAdapter: BaseQuickAdapter<DownloadEntity, QuickViewHolder>() {

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): QuickViewHolder {
        // 返回一个 ViewHolder
        return QuickViewHolder(R.layout.item_download, parent)
    }

    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: DownloadEntity?) {
        // 设置item数据
        if (item == null) return
        holder.setText(R.id.btn_start, item.downloadTag)
            .setText(R.id.tv_task_status, Status.getStatusName(item.state))
            .setText(R.id.tv_task_speed, ConvertUtils.byte2FitMemorySize(item.speed, 0))
            .setText(R.id.tv_task_length, ConvertUtils.byte2FitMemorySize(item.contentLength, 0))
            .setText(R.id.tv_task_percent, "${(item.percent).toInt()}%")

    }


}